package com.sky.controller.admin;

import com.sky.constant.JwtClaimsConstant;
import com.sky.dto.EmployeeDTO;
import com.sky.dto.EmployeeLoginDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.param.EemInsertParam;
import com.sky.pojo.Employee;
import com.sky.properties.JwtProperties;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.EmployeeService;
import com.sky.utils.JwtUtil;
import com.sky.vo.EmployeeLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 员工管理
 */
@RestController
@RequestMapping("/admin/employee")
@Slf4j
@Api(tags = "员工管理")
public class EmployeeController {
    @Autowired
    EmployeeService employeeService;

    @PostMapping("/login")
    @ApiOperation("员工登录")
    public Result<EmployeeLoginVO> login(@RequestBody EmployeeLoginDTO employeeLoginDTO) {
        log.info("员工登录：{}", employeeLoginDTO);
        return employeeService.login(employeeLoginDTO);
    }

    @PostMapping("/logout")
    @ApiOperation("员工退出")
    public Result<String> logout() {
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("分页查询员工信息")
    public Result<PageResult> page(EmployeePageQueryDTO empDto) {
        return employeeService.selectEmpbyPage(empDto);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询员工信息")
    public Result<EmployeeDTO> getById(@PathVariable Long id) {
        return Result.success(employeeService.getById(id));
    }

    @PostMapping
    @ApiOperation("新增员工")
    public Result insert(@RequestBody EemInsertParam param) {
        Employee insert = employeeService.insert(param);
        log.info("新增员工：{}", insert);
        return Result.success("新增成功");
    }

    @PostMapping("/status/{status}")
    @ApiOperation("启用禁用员工账号")
    public Result status(@PathVariable Integer status, Long id) {
        log.info("启用禁用员工{}账号：{}", id, status);
        int result = employeeService.status(status, id);
        return Result.success();
    }

    @PutMapping
    @ApiOperation("修改员工信息")
    public Result update(@RequestBody EemInsertParam param) {
        int update = employeeService.update(param);
        return Result.success("成功更新数据："+update);
    }


}
